package cn.jiyun.controller;

import cn.hutool.jwt.JWTUtil;
import cn.jiyun.entity.Menber;
import cn.jiyun.entity.Result;
import cn.jiyun.entity.ResultClass;
import cn.jiyun.service.FenigService;
import cn.jiyun.service.MenberService;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author weiyuanhang
 * @data: 2023/8/22 002211:15
 * @Package cn.jiyun.controller
 * @email 3185757326@qq.com
 */
@RestController
@RequestMapping("/menber")
public class MenberController {
    @Autowired
    private MenberService menberService;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private FenigService fenigService;
    @PostMapping("/menberLogin")
    public Result menberLogin(@RequestBody Menber menber){
          return Result.ok(fenigService.userLogin(menber));
    }

    @GetMapping("/findLoginUser")
    public ResultClass findLoginUser(HttpServletRequest request){
        String token = request.getHeader("token");
        Menber user = JSON.parseObject((String) redisTemplate.opsForValue().get(token), Menber.class);
        return ResultClass.ok(ResultClass.ok(user));
    }
}
